/**
 * Created by novem on 2015/10/21.
 */
function pi(){
    return  3.1415926535898;
}
pow=Math.pow;
sin=Math.sin;
cos=Math.cos;
asin=Math.asin;
min=Math.min;
sqrt=Math.sqrt;
window.onload=function(){
    //表头滑动
    var mySwiper1 = new Swiper('#w_thua',{
        freeMode : true,
        slidesPerView : 'auto'
        // loop : true,
    });
    var url= getUrl();
    var loc = getLoc();
    $.jsonp({
        url: 'http://'+url+'/api/rcar/rcar_list',
        data: {},
        callbackParameter: "callback",
        success: function (data, textStatus, xOptions) {
            $.each(data.array,function(index,item) {
                earthRadius = 6371;
                var lat0 = (loc.lat * pi()) / 180;
                var lng0 = (loc.lng * pi()) / 180;
                var lat1 = (item.rcardimensions * pi()) / 180;
                var lng1 = (item.rcarLongitude * pi()) / 180;
                calcLongitude = lng1 - lng0;
                calcLatitude = lat1 - lat0;
                stepOne = pow(sin(calcLatitude / 2), 2) + cos(lat0) * cos(lat1) * pow(sin(calcLongitude / 2), 2);
                stepTwo = 2 * asin(min(1, sqrt(stepOne)));
                calculatedDistance = earthRadius * stepTwo;
                item.distance=calculatedDistance;
            });
            var complied_tpl = juicer($("#car_tpl").text());
            var html = complied_tpl.render(data);
            $("#car_list").append(html);
        },
        error: function (xOptions, textStatus) {
        }
    });
}

function jump(url){
    var spotsId = $.getUrlParam('id');
    location.href=url+'?id='+spotsId
}